Download presentation
Presentation is loading. Please wait.
Published byΔαίμων Γερμανού Modified over 5 years ago
1
CMPE 135: Object-Oriented Analysis and Design March 19 Class Meeting
Department of Computer Engineering San Jose State University Spring 2019 Instructor: Ron Mak
2
Midterm Solution: Question #41
Briefly describe how delegation can help to encapsulate changes. A class delegates functionality or behavior to another class that it aggregates. Delegation is often used for functionality/behavior that can vary. Therefore, the delegate class is encapsulating what can change.
3
Midterm Solution: Question #42
How would you write the declaration of a pure virtual member function named foo that takes no parameters and returns void? virtual void foo() = 0;
4
Midterm Solution: Question #43
Briefly describe how the principle of Coding to the Interface and polymorphism work together. You have a superclass (the interface) that has several subclasses. Each subclass overrides one or more member functions of the superclass. You have a target variable that has the superclass type. At run time, you code to the interface by assigning to that target variable an object instantiated from one of the subclasses. Then when you call an overridden member function on the target variable, polymorphism determines which subclass’s member function is called depending on the subclass type of the instantiated object.
5
Midterm Solution: Question #44
Briefly describe how the principle of Coding to the Interface and a factory class work together. You have a superclass (the interface) that has several subclasses. You code to the interface by having a target variable that has the superclass type. At run time, you need the flexibility to assign to the target variable an object instantiated from any one of the subclasses. You can use a factory class with a create function that creates and returns a pointer to such an object. An argument to the create function determines which subclass it instantiates, and the argument’s value is set at run time.
6
Midterm Solution, cont’d
Date Calendar Gregorian Lunar Calendar *cal = CalendarFactory::create(type); cal->set(Calendar::YEAR, 2019); cal->set(Calendar::MONTH, Calendar:: FEBRUARY); cal->set(Calendar::DATE, 14);
7
wx-RPS: MacOS X
8
wx-RPS: Linux
9
wx-RPS: Windows 10 Why does the app look so ugly on Windows?
10
Tutorials My tutorials: Install VirtualBox Install Ubuntu Install wxWidgets on Ubuntu
11
Install wxWidgets on Mac OS X
On the command line: This will install wxWidgets in /usr/local/Cellar/wxmac/3.0.4_1 See: brew install wxmac
12
Create wxWidgets Apps in Eclipse
Create a C++ project in Eclipse and open the Properties dialog box. In the left panel, select C/C++ Build | Settings
13
Create wxWidgets Apps in Eclipse, cont’d
GCC C++ Compiler Dialect: Includes: Include paths Preprocessor: Defined symbols (-D) Miscellaneous: Other flags C++11 /usr/local/Cellar/wxmac/3.0.4_1/lib/wx/include/osx_cocoa-unicode-static-3.0 /usr/local/Cellar/wxmac/3.0.4_1/include/wx-3.0 __WXOSX_COCOA__ WXUSINGDLL _FILE_OFFSET_BITS=64 -c -mmacosx-version-min= fmessage-length=0 -fvisibility=hidden -fvisibility-inlines-hidden
14
Create wxWidgets Apps in Eclipse, cont’d
MacOS X C++ Linker Libraries (-l) Library search path (-L) Miscellaneous: Linker flags (one long line) wx_osx_cocoau_adv-3.0 wx_osx_cocoau_core-3.0 wx_baseu-3.0 png z jpeg lzma pthread iconv /usr/local/Cellar/wxmac/3.0.4_1/lib -mmacosx-version-min= framework IOKit -framework Carbon -framework Cocoa -framework AudioToolbox -framework System -framework OpenGL -framework OpenGL -framework Security
15
Button Demo
16
Button Demo, cont’d ButtonPanel.h class ButtonPanel : public wxPanel {
ButtonPanel(wxFrame *parent) : wxPanel(parent, wxID_ANY) { init(); } // Event handlers void on_rock(wxCommandEvent& event); void on_paper(wxCommandEvent& event); void on_scissors(wxCommandEvent& event); private: wxStaticText *button_chosen_text; void init(); void update_button_choice_text(const Choice choice); };
17
Button Demo, cont’d ButtonPanel.cpp #include "ButtonPanel.h"
void ButtonPanel::init() { wxSizer *sizer = new wxBoxSizer(wxVERTICAL); wxPanel *button_panel = new wxPanel(this, wxID_ANY); wxSizer *button_sizer = new wxBoxSizer(wxHORIZONTAL); wxStaticText *choose_text = new wxStaticText(button_panel, wxID_ANY, "Choose:"); wxButton *rock_button = new wxButton(button_panel, wxID_ANY, choice_to_wxString(ROCK)); wxButton *paper_button = new wxButton(button_panel, wxID_ANY, choice_to_wxString(PAPER)); wxButton *scissors_button = new wxButton(button_panel, wxID_ANY, choice_to_wxString(SCISSORS)); ...
18
Button Demo, cont’d ... rock_button->Bind (wxEVT_BUTTON, &ButtonPanel::on_rock, this); paper_button->Bind (wxEVT_BUTTON, &ButtonPanel::on_paper, this); scissors_button->Bind(wxEVT_BUTTON, &ButtonPanel::on_scissors, this); button_sizer->Add(choose_text, 0, 0, 0); button_sizer->AddSpacer(5); button_sizer->Add(rock_button, 0, 0, 0); button_sizer->Add(paper_button, 0, 0, 0); button_sizer->Add(scissors_button, 0, 0, 0); button_panel->SetSizer(button_sizer); wxPanel *chosen_panel = new wxPanel(this, wxID_ANY); wxSizer *chosen_sizer = new wxGridSizer(2, 0, 5);
19
Button Demo, cont’d ... wxStaticText *chosen_text = new wxStaticText(chosen_panel, wxID_ANY, "Chosen object:"); button_chosen_text = new wxStaticText(chosen_panel, wxID_ANY, ""); button_chosen_text->SetFont(button_chosen_text->GetFont().Larger()); chosen_sizer->Add(chosen_text, 0, wxALIGN_RIGHT, 0); chosen_sizer->Add(button_chosen_text, 0, 0, 0); chosen_panel->SetSizer(chosen_sizer); sizer->Add(button_panel, 0, wxALIGN_CENTER, 0); sizer->AddSpacer(20); sizer->Add(chosen_panel, 0, wxALIGN_CENTER, 0); SetSizer(sizer); }
20
Button Demo, cont’d void ButtonPanel::on_rock(wxCommandEvent& event) {
update_button_choice_text(ROCK); } void ButtonPanel::on_paper(wxCommandEvent& event) update_button_choice_text(PAPER); void ButtonPanel::on_scissors(wxCommandEvent& event) update_button_choice_text(SCISSORS); void ButtonPanel::update_button_choice_text(const Choice choice) button_chosen_text->SetLabelText(choice_to_wxString(choice));
21
Assignment #5. GUI-Based RPS Game
Develop an GUI-based version of your Rock-Paper-Scissors game. Sample:
22
Assignment #5, cont’d Minimum features Which round
A way for the user to enter a choice for each round. The computer’s prediction of the human’s choice for the round. The computer’s choice for the round. Who the winner is (or is it a tie) of the round. The number of human and computer wins, and the number of ties.
23
Assignment #5, cont’d Menu commands The default is 20 rounds per game.
About Exit Start a new game The default is 20 rounds per game. Provide a way for the human player to change that number. Due Monday, April 8 (after Spring Break)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.