Update MP2
This commit is contained in:
82
Assignments/MP2_CalebFontenot/main.cpp
Normal file
82
Assignments/MP2_CalebFontenot/main.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/cppFiles/main.cc to edit this template
|
||||
*/
|
||||
|
||||
/*
|
||||
* File: main.cpp
|
||||
* Author: caleb
|
||||
*
|
||||
* Created on March 4, 2024, 7:18 PM
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <ncurses.h>
|
||||
|
||||
using namespace std;
|
||||
#include "rockPaperScissors.h"
|
||||
#include "main.h"
|
||||
|
||||
int main(){
|
||||
int ch;
|
||||
static int selection = 0;
|
||||
static int * selectionPointer = &selection;
|
||||
initscr();
|
||||
raw();
|
||||
keypad(stdscr, TRUE);
|
||||
noecho();
|
||||
//clear();
|
||||
|
||||
while ((ch = getch()) != '#') {
|
||||
switch(ch) {
|
||||
case KEY_UP:
|
||||
printw("\nUp %i\n", --selection);
|
||||
break;
|
||||
|
||||
case KEY_DOWN:
|
||||
printw("\nDown %i\n", ++selection);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// Ensure selection stays within bounds
|
||||
selection = (selection < 0) ? 0 : selection;
|
||||
selection = (selection > 2) ? 2 : selection;
|
||||
printw("%s", printMenu(selectionPointer).c_str());
|
||||
}
|
||||
|
||||
|
||||
refresh();
|
||||
getch();
|
||||
endwin();
|
||||
}
|
||||
|
||||
|
||||
std::string printMenu(int* selection) {
|
||||
const int ARRAY_SIZE = 3;
|
||||
std::string outputString = "";
|
||||
std::string cursor[ARRAY_SIZE] = {"> ", " ", " "};
|
||||
std::string menu[ARRAY_SIZE] = {"Rock Paper Scissors", "2D Arrays", "Binary Search"};
|
||||
printf("%i", *selection);
|
||||
if (*selection >= ARRAY_SIZE - 1) {
|
||||
*selection = 0;
|
||||
}
|
||||
if (*selection < 0) {
|
||||
*selection = ARRAY_SIZE - 1;
|
||||
}
|
||||
|
||||
std::string temp = cursor[0];
|
||||
for (int j = 0; j < *selection; ++j) {
|
||||
printf("cursor %i\n", j);
|
||||
cursor[j] = cursor[j + 1];
|
||||
}
|
||||
cursor[0] = temp;
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE; ++i) {
|
||||
outputString.append(cursor[i]);
|
||||
outputString.append(menu[i]);
|
||||
outputString.append("\n");
|
||||
}
|
||||
return outputString;
|
||||
}
|
Reference in New Issue
Block a user